<?php
/**
 * This Online controller handdling ebay and online website 
 * it has two functions 
 * 1. upload new products
 * 2. stock control for ebay and website (phonecollection at the moent)
 * 3. packing , packing is in the eb2 folder and password protected (ebaylabel/label123456)
 * @author Norman
 *
 */
class OnlineController extends Zend_Controller_Action
{
	
	/**
	 * this is the landing page contain all the links 
	 */
	public function indexAction(){
		
	}
	

	/**
	 * this is the prepare page only demo and file download link no functions
	 */
	public function onlineStep1Action(){
		//echo "Import the Excel File";
		// importing the excel file
	}
	/**
	 * instructions to upload the file no functions
	 */
	public function onlineStep2Action(){
		// get ready the missing pictures
	}	
	/**
	 * prepare the file upload 
	 * the Excel file structed in Step 1 will be use to put details into database
	 * it will be input into product_detail table
	 * 
	 */
	public function onlineStep3Action(){
		// double verify information before produce the result
		set_time_limit(0);
		$data = new Model_Products_Detail();//for insert
		$fdata = new Model_Fileshandler();//excel to array
		$dva = new Model_DbTable_Productsva();
		$flexPrice = new Model_DbTable_Products_Price_Flexprice();
		
		$mydata = array();
		
		$introduced = Model_DatetimeHelper::dateToday();
		
		$id = 0;
		
		if($_POST){
			if(move_uploaded_file($_FILES['fileField']['tmp_name'], getcwd()."/".$_FILES['fileField']['name'])){
				$mydata = $fdata->excel2array(getcwd()."/".$_FILES['fileField']['name']);
				
				//dd($mydata);
				$cot1 = 0;
				$cot2 = 0;
				foreach($mydata as $v){
				$row = $dva->getProductID(trim($v['B']));
				
				if($row == false){
					echo "New Product,Insert Into Product Database".'<br>';
					$id = $dva->addProduct(trim(strtoupper($v['B'])),$v['D']);
				}
				else{
					$id = $row;
				}
				//$data->addDetail($idProduct, $codeProduct, $aposTitle, $mobileBrand, $mobileModel, $category, $shortDescriptionProduct, $chineseTitleProduct, $descriptionProduct, $webpageDescription, $feature, $sizeMm, $weightKg, $introduced, $imgUrl, $imgIndiUrl, $imgZip, $nameSupplier, $barcodeSupplier, $ebayCategory, $postage)
				
				$idLine = $data->getDetail($id);
				if(!$idLine){
					$data->addDetail($id,trim(strtoupper($v['B'])),$v['D'],$v['G'], $v['H'], $v['I'], $v['J'],$v['C'], $v['L'], $v['K'], $v['M'], $v['N'], $v['O'], $introduced, $v['Q'], $v['R'], $v['S'], $v['T'], $v['U'], $v['AB'], $v['V'],$v['W']);
					$cot1++;
				}
				else{
					$data->updateDetail($id,trim(strtoupper($v['B'])),$v['D'],$v['G'], $v['H'], $v['I'], $v['J'],$v['C'], $v['L'], $v['K'], $v['M'], $v['N'], $v['O'], $introduced, $v['Q'], $v['R'], $v['S'], $v['T'], $v['U'], $v['AB'], $v['V'],$v['W']);
					$cot2++;
				}
				$flexPrice->conditionalInsert($id,1, $v['Y'],$introduced);
				$flexPrice->conditionalInsert($id,2, $v['Z'], $introduced);
				$flexPrice->conditionalInsert($id,3, $v['X'], $introduced);
				
				}
				
				echo "{$cot1} New Records has been Added , {$cot2} Records has been Updated,Both Of Them, Date of Update/Introduce Are Set to Today";
			}
			else{
				
				echo "File Upload Failed!!";
			}
			
			
		}
		
		
		
	}
	/**
	 * This step is for produce the ebay file exchange file for turbo list 
	 * or the csv for imported into prestashop
	 * by select what you want to import, it product the csv and store into 
	 * 
	 */
	public function onlineStep4Action(){
		//produce the file for upload
		$pDetail = new Model_Products_Detail();
		$flexPrice = new Model_DbTable_Products_Price_Flexprice();
		$pList = array();
		if($_POST){
			$dateUpdate = $_POST['date_check'];
			
			$dlist= $pDetail->listUpdatedByDate($dateUpdate);

			if(!empty($dlist)){
				foreach($dlist as $k => $v){
					$tmpArr = $v;
					
					$ebPrice = $flexPrice->getFprice($v['id_product'],3);
					$lvPrice = $flexPrice->getFprice($v['id_product'],1);
					$phPrice = $flexPrice->getFprice($v['id_product'],2);
					
					$tmpArr['ebay_price'] = $ebPrice['flex_price'];
					$tmpArr['lv_price'] = $lvPrice['flex_price'];
					$tmpArr['ph_price'] = $phPrice['flex_price'];
					$tmpArr['apos_stock'] = file_get_contents('http://192.168.1.126/products/get-current-stock/barcode/'.$v['code_product']);
					
					// check image 
					$wholeImg = $v['img_url'];
					$indImg = $v['img_individual_url'];
					$imgFolder = getcwd().'/product_img/home_img/';
					
					$tmpArr['w_exist'] = (file_exists($imgFolder.$wholeImg))?"OK":"N/A";
					$tmpArr['i_exist'] = (file_exists($imgFolder.$indImg))?"OK":"N/A";

					$pList[] = $tmpArr;
				}
			}
		}
		$this->view->pList = $pList;
		
	}
	
	/**
	 * this is the acutal page to do the generate file action
	 */
	
	public function onlineStep5Action(){
		//verify upload is OK, it is DONE
		$pro = new Model_DbTable_Productsva();
		
		if($_POST){
			
			foreach($_POST['ept_ebay'] as $k => $v){
				
				if($_POST['shop_csv'] == 1){
					$bcode = $pro->getProduct($k);
					echo $str = file_get_contents("http://192.168.1.124/products/generate-presta-shop-csv/shop/phonecollection/code_product/".trim($bcode['code_product']));
				}
				else{
					$bcode = $pro->getProduct($k);
					echo $str = file_get_contents("http://192.168.1.124/products/generate-ebay-listing/code_product/".trim($bcode['code_product']));
				}
			}
		}
		
		
	}
	/**
	 * this is the main page of stock control 
	 * you need to download the ebay Active file to do the job
	 * for K-mobile account , 0 stock has been opened 
	 * when the stock set to 0 , it still active.
	 * so you don't have to end that list 
	 * this page will using the ebay active file 
	 * check the ebay id and stock then input into product_web table
	 */
	public function stockControlAction(){
		 // download file and upload file , produce result 
		$eFile = new Model_Exchangefilehandler();
		$pWeb = new Model_Products_Webproduct(); 
		$pro = new Model_DbTable_Productsva();
		if($_POST){
		 	if(move_uploaded_file($_FILES['upload_file']['tmp_name'],getcwd().'/'.$_FILES['upload_file']['tmp_name'])){
		 			$pWeb->markUnavailable("ebay","k-mobile");
		 			$arrActive = $eFile->readEbayActiveCsv(getcwd().'/'.$_FILES['upload_file']['tmp_name']);
		 			foreach($arrActive as $k => $v){
		 				$idProduct = $pro->getProductID(trim($v[1]));
		 				$pWeb->conditionalAddWebProduct($idProduct, $v[1],'ebay','k-mobile',$v[0],$v[2]);
		 			}
		 	echo "File Uploaded, You may Go to Next Step";
		 	$this->_redirect("/online/stock-control2");
		 	}
		 }
		 
	}
	
	/**
	 * after the ebay current status is uploaded into the system 
	 * using the link in this page to produce 2 files
	 * 1. warehouse has no stock the item is on ebay
	 * 2. warehouse has stock the item is not on ebay
	 */
	public function stockControl2Action(){
		// upload result to ebay, direct manage website
		//generate relist and End List 
		$pWeb = new Model_Products_Webproduct(); 
		// Relist 
		
		
		
		
		// EndList 
		// revise Qty
		// revise Price 
		
		
	}
	
	/**
	 * Ended item relst list , this function has NOT too much use
	 * because we do not end item that much
	 */
	public function stockControlRelistAction(){
		
		set_time_limit(0);
		
		date_default_timezone_set('Australia/Melbourne');
		$filename = "ebay_relist_".date("Y_m_d").".csv";
		$folder = getcwd()."/export/ebay/";
		if(!file_exists($folder.$filename)){
		$titlearray = array('Action(SiteID=Australia|Country=AU|Currency=AUD|Version=403|CC=UTF-8)','ItemID','StartPrice');
		$fp=fopen($folder.$filename,"a");
		fputcsv($fp,$titlearray);
		fclose($fp);
		}
		$pWeb = new Model_Products_Webproduct();
		$flexPrice = new Model_DbTable_Products_Price_Flexprice();
		$idCategory = 3; // eBay Category 
		
		//find item NOT on line
		$rList = $pWeb->findNotOnline("ebay","k-mobile");
		
		
		if($rList){
			$fp=fopen($folder.$filename,"a");
		foreach($rList as $k => $v){
			
			$codeProduct = trim($v['code_product']);
			$idProduct = $v['id_product'];
			$stock = file_get_contents('http://192.168.1.126/products/get-current-stock/barcode/'.$codeProduct);
			$priceArr = $flexPrice->getPriceByIDCategory($idProduct, $idCategory);
			$eBayPrice = $priceArr['flex_price'];
			
			if($stock > 10){
				fputcsv($fp,array('Relist',$v['id_on_website'],$eBayPrice));
			}
			
		}
			fclose($fp);
		
		echo "Relist List is Ready Please Download <a href='/export/ebay/{$filename}' target ='_blank' >Here</a>";
		
		}	
	}
	
	/**
	 * if item out of stock , the Qty of the item need to set to 0
	 */
	public function stockControlOutOfStockAction(){
		
		set_time_limit(0);
		
		date_default_timezone_set('Australia/Melbourne');
		$filename = "ebay_out_of_stock_".date("Y_m_d").".csv";
		$folder = getcwd()."/export/ebay/";
		if(!file_exists($folder.$filename)){
		$titlearray = array('Action(SiteID=Australia|Country=AU|Currency=AUD|Version=403|CC=UTF-8)','ItemID','Quantity');
		$fp=fopen($folder.$filename,"a");
		fputcsv($fp,$titlearray);
		fclose($fp);
		}
		//$fp = fopen
		$fp=fopen($folder.$filename,"a");
		
		$pWeb = new Model_Products_Webproduct();
		$posList = $pWeb->findAllOnline("ebay", "k-mobile");
		
		
		foreach($posList as $k => $v){
			// check if have stock 
			$codeProduct = trim($v['code_product']);
			$idProduct = $v['id_product'];
			
			$stock = file_get_contents('http://192.168.1.126/products/get-current-stock/barcode/'.$codeProduct);
			if($stock < 10){
				fputcsv($fp,array('Revise',$v['id_on_website'],0));
			}
			
		}
		
		fclose($fp);
		
		echo "Out Of Stock  List is Ready Please Download <a href='/export/ebay/{$filename}' target ='_blank' >Here</a>";
		
	}
	/**
	 * Back to Stock list , when warehouse has stock , using this one to alert the qty to 3 so the item appear in ebay again
	 */
	public function stockControlBackStockAction(){
		
		set_time_limit(0);
		
		date_default_timezone_set('Australia/Melbourne');
		$filename = "ebay_back_stock_".date("Y_m_d").".csv";
		$folder = getcwd()."/export/ebay/";		
		
		//just revise Qty to 3
		if(!file_exists($folder.$filename)){
		$titlearray = array('Action(SiteID=Australia|Country=AU|Currency=AUD|Version=403|CC=UTF-8)','ItemID','Quantity');
		$fp=fopen($folder.$filename,"a");
		fputcsv($fp,$titlearray);
		fclose($fp);
		}
		//
		$fp=fopen($folder.$filename,"a");
		
		$pWeb = new Model_Products_Webproduct();
		$pboList = $pWeb->findNoStockActive("ebay", "k-mobile");		

		foreach($pboList as $k => $v){
			// check if have stock
			$codeProduct = trim($v['code_product']);
			$idProduct = $v['id_product'];
				
			$stock = file_get_contents('http://192.168.1.126/products/get-current-stock/barcode/'.$codeProduct);
			if($stock >= 10){
				fputcsv($fp,array('Revise',$v['id_on_website'],3)); // all set to 3 items
			}
				
		}
		
		fclose($fp);
		
		echo "Back To Stock List is Ready Please Download <a href='/export/ebay/{$filename}' target ='_blank' >Here</a>";
		
	}
	/**
	 * this function is not in use ,when item out of stock 
	 * we don't end it any more , we just put it into 0 stoc qty
	 */
	
	public function stockControlEndOfLifeAction(){
		set_time_limit(0);
		
		date_default_timezone_set('Australia/Melbourne');
		$filename = "ebay_eof_".date("Y_m_d").".csv";
		$folder = getcwd()."/export/ebay/";
		
		if(!file_exists($folder.$filename)){
		$titlearray = array('Action(SiteID=Australia|Country=AU|Currency=AUD|Version=403|CC=UTF-8)','ItemID','EndCode');
		$fp=fopen($folder.$filename,"a");
		fputcsv($fp,$titlearray);
		fclose($fp);
		}
		
		$fp=fopen($folder.$filename,"a");

		$pWeb = new Model_Products_Webproduct();
		$peList = $pWeb->findAllOnline("ebay","k-mobile");
		
		foreach($peList as $k => $v){
		// find item in dispose list , then set to EOF
		// Can not do it now 	
		//array("End",$itemID,"NotAvailable");	
			
		}
	}
	/**
	 * this is for revise the price and title
	 * if the item detail table been updated
	 * it will produce this file 
	 * after you upload the price and title of the product will be modified
	 */
	public function stockControlPriceTitleReviseAction(){
		
		set_time_limit(0);
		
		date_default_timezone_set('Australia/Melbourne');
		$filename = "ebay_revise_price_title_".date("Y_m_d").".csv";
		$folder = getcwd()."/export/ebay/";
		if(!file_exists($folder.$filename)){
		$titlearray = array('Action(SiteID=Australia|Country=AU|Currency=AUD|Version=403|CC=UTF-8)','ItemID','Title','StartPrice');
		$fp=fopen($folder.$filename,"a");
		fputcsv($fp,$titlearray);	
		fclose($fp);
			}
		// find all updat Today
			$fp=fopen($folder.$filename,"a");

		$pDetail = new Model_Products_Detail();
		$proWeb = new Model_Products_Webproduct();
		$flexPrice = new Model_DbTable_Products_Price_Flexprice();
		
		$idCategory = 3; //ebay Price Category 
		
		
		
		$puList = $pDetail->listLastUpdate(Model_DatetimeHelper::dateToday());
		
		
		foreach($puList as $k=> $v){
			$idProduct = $v['id_product'];
			$title = $v['short_description_product'];	
			$priceRow = $flexPrice->getPriceByIDCategory($idProduct, $idCategory);	
			$price = $priceRow['flex_price'];
			$webRow = $proWeb->fetchWebId($v['code_product'],"ebay","k-mobile");
			if($webRow){
			fputcsv($fp,array("Revise",$webRow['id_on_website'],$title,$price));
			}
			}
		
		fclose($fp);
		
		echo "Price Title Change List is Ready Please Download <a href='/export/ebay/{$filename}' target ='_blank' >Here</a>";
		
	}
	/**
	 * this fuction is using ftp automaticlly upload file 
	 * we have 3 webservers so we need to use ftp upload to 3 different place
	 * this page find anything later than today, which is newled upload 
	 */	
	public function uploadNewFileAction(){
		set_time_limit(0);
		$mail = new Model_Emailshandler();
		$mailBody = "";
		
		
		$ftp = new Model_System_Ftphelper();
		
		$arrImage  = $ftp->getNewFileList();
		d($arrImage);
		foreach($arrImage as $fileName){
			$cot1 = 0;
			while(!($res1 = $ftp->uploadNg($fileName)) && $cot1 < 3){
				sleep(3);
				$cot1++;
				$mailBody .= 'NG:{$fileName} Upload Failed For '.$cot1.'<br />';
			}
			$cot2 = 0;
			
			while(!($res2 = $ftp->uploadLb($fileName)) && $cot2 < 3){
				sleep(3);
				$cot2++;
				$mailBody .= 'LB:{$fileName} Upload Failed For '.$cot2.'<br />';
			}
			
			$cot3 = 0;
			
			while(!($res3 = $ftp->uploadPc($fileName)) && $cot3 < 3){
				sleep(3);
				$cot3++;
				$mailBody .= 'PC:{$fileName} Upload Failed For '.$cot3.'<br />';
			}
		
		
		}
		
		if(trim($mailBody)!=""){
			
			$mail->sendNormalEmail("eco3@phonecollection.com.au","Upload Failed Log", $mailBody);
		}
	}

	public function pcStockControlAction(){
		set_time_limit(0);
		
		$psStock = new Model_Ps_Psstock(Zend_Registry::get('db_remote'));
		$psProduct =  new Model_Ps_Psproducts(Zend_Registry::get('db_remote'));
		$psAttr = new Model_Ps_Psattribute(Zend_Registry::get('db_remote'));
		
		$pList = $psStock->listAll();
		
		//d($pList);
		
		foreach($pList as $pRow){
			if($pRow['id_product_attribute'] == 0){
				// single products
				$idProduct = $pRow['id_product'];
				$pLine = $psProduct->getPsproducts($idProduct);
				//  find the barcode 
				$barCode = strtoupper(trim($pLine['reference']));
				$stock = file_get_contents("http://192.168.1.126/products/get-current-stock/rt/1/barcode/".$barCode);
				
				if($stock !='na'){
					// update stock 
					$psStock->updateStockQty($stock, $pRow['id_stock_available']);
					echo "Find Update: ".$barCode."<br />";
				}
				else{
					// parepare for force 	
				echo $barCode.",<br />";	
				}
			
				
			}
			else{
				// products with attribute 
				$idAttr =  $pRow['id_product_attribute'];
				$pLine = $psAttr->getPsattribute($idAttr);
				$barCode = strtoupper(trim($pLine['reference']));
				$stock = file_get_contents("http://192.168.1.126/products/get-current-stock/rt/1/barcode/".$barCode);
				
				if($stock !='na'){
					// update stock, update qty in the att 
					$psStock->updateStockQty($stock, $pRow['id_stock_available']);
					$psAttr->updateAttributeQty($stock, $idAttr);	
					echo "Find Update: ".$barCode."<br />";
				}
				else{
					// parepare for force
					echo $barCode.",<br />";
				}
					
			}
			
			
		}
		
		//list all stock avail 
		// find barcode in products or in attribute 
		// get stock qty (Wh) 
		// 
		
		
	}
	
	public function getPackingMethodAction(){
		
		$this->_helper->layout->disableLayout();
		
		$barCode = $this->_getParam('barcode');
		$proWeb = new Model_Products_Webproduct();
		$packMethod = $proWeb->getPackingMethod($barCode,'ebay','k-mobile');
		
		echo $packMethod;
		
		
		
	}
	
	public function publicCheckAvailabilityAction(){
		$arrShop = unserialize(ARR_SHOP_ACTIVE);
		
		
	}
	/**
	 * Add by Norman This Function run on 126
	 * This function Run every 5 mins
	 */
	public function onlineOrderControlAction(){
		
		date_default_timezone_set("Australia/Melbourne");
		
		
		/**
		 * Setp 1 : run every five mins check if there new order 
		 */
		$arrCarrier = unserialize(PS_CARRIER_SHOP_MAPPING);
		$sysConfig = new Model_DbTable_Systemconfig(Zend_Registry::get('db_real'));
		$onlineOrder = new Model_Ps_Onlineorders(Zend_Registry::get('db_remote'));
		$carrier = new Model_Ps_Ordercarrier(Zend_Registry::get('db_remote'));
		$shopHeads = new Model_DbTable_Shoplocation(Zend_Registry::get('db_real'));
		$monitor = new Model_DbTable_Onlineordermonitor(Zend_Registry::get('db_real'));
		
		$mail = new Model_Emailshandler();
		
		
		$idOrderSys = $sysConfig->gV('PS_ORDER_COT');
		$lastOrder = $onlineOrder->getLatestOrder();
		
		//d($idOrderSys,$lastOrder);
		if($lastOrder > $idOrderSys){
			$idCarrier = $carrier->getOrdercarrier($idOrderSys + 1);
			$shopName = $arrCarrier[$idCarrier['id_carrier']];
			if($shopName != 'WHPC'){
				$currentHour = Date("H");
				//d($shopName);
				// find shop email and 
				$shopEmail = $shopHeads->getShopMailByHead($shopName);
				//$shopEmail = 'eco1@phonecollection.com.au';
				$mail->getAndRemoveOrders($shopEmail);
				// put into company info page 
				
				$monitor->addOrder($idOrderSys + 1,$shopName,Model_DatetimeHelper::dateToday(),$currentHour,1);
			}
			else{
				
				$shopEmail = 'eco3@phonecollection.com.au';
				$mail->getAndRemoveOrders($shopEmail);
				
			}
			 
		// there is new order , replace the latest order no .
		$sysConfig->upV('PS_ORDER_COT',$idOrderSys+1);		
		
		//record this no to 
			
		}
		//else do nothing 
		
		
		// if there is new order , check if the new order carrier is post , if not record the new put into the latest number , 
		// if carrier new order is not post , then modify email with instructions , find the shop and send to shop Immediatelly.
		
		
		// if there is No new order  do nothing this part
		
		
		
		
		// check old order status id = 1 waiting for shop confirmation reservation has been solved 
		// if solved do nothing 
		// if not solved according time notify shop manager 
		
	}
	
	public function updateOnlineOrderStatusAction(){
			
			$idOrder = $this->_getParam("id_order");
			$status =  $this->_getParam("status");
			
			Model_Ps_Orderstatusupdate::updateStatus($idOrder, $status);
			Model_Ps_Orderstatusupdate::updateStatusHistory($idOrder, $status);
		
		
	}
	/**
	 * run on 126
	 */
	public function exportForExcelAction(){
		
		$ifAll = $this->_getParam('all');

		
		set_time_limit(0);

	
		
		$arrRun = array();
		
		
		
		$psAtt = new Model_DbTable_Psattribute();
		$psImg = new Model_DbTable_Psproimage();
		$psAttImg = new Model_DbTable_Psattimage();
		$loc = new Model_Products_Location();
		
		
		$proDetail = new Model_Products_Detail();
		
		
		$list = $proDetail->listAll();
		foreach($list as $line){
			
			$arrRun[]  = $line['code_product'];
		}
		
		
		$pModel = new Model_DbTable_Barcodemodel();
		$pmList = $pModel->listAllModel();
		
		$paList = $psAtt->listAll();
		$color = new Model_DbTable_Barcodecolorcodes();
		
		$cot = 0;
		$arrRes = array();
		
		$fileName = "ebayListing".Model_DatetimeHelper::dateToday('').rand(0,99).".csv";
		$fl = fopen($fileName,"a");
		$web = new Model_Products_Webproduct();
		
		foreach($arrRun as $barcode){
			//get barcode
			if(trim($barcode)!=''){
				$whStock = file_get_contents('http://192.168.1.126/products/get-current-stock/barcode/'.trim($barcode));
				//$idWeb = $web->fetchWebId($barcode,"ebay","k-mobile");
					
				if($whStock > 10 ){
					$cot ++;
					$tmpArr = array();
					$tmpArr[] = 'NO'; // new products
					$tmpArr[] = trim($barcode); // barcode
					$tmpArr[] = '';//chinese title
					$aposTitle = file_get_contents('http://192.168.1.126/products/get-old-apos-product-description/barcode/'.trim($barcode));
					$tmpArr[] = $aposTitle;//apos title
					$tmpArr[] = Model_DatetimeHelper::dateToday();//first date
					$tmpArr[] = '';//inital stock empty
					$brand = '';
					Switch(substr($barcode,0,2)){
						case('AP'):{
							$brand = 'Apple';break;
						}
						case('HT'):{
							$brand = 'HTC';break;
						}
						case('SA'):{
							$brand = 'Samsung';break;
						}
						case('NO'):{
							$brand = 'Nokia';break;
						}
						case('UI'):{
							$brand = 'Universal';break;
						}
						case('LG'):{
							$brand = 'LG';break;
						}
						case('SE'):{
							$brand = 'Sony';break;
						}
							
					}
		
					$tmpArr[] = $brand;//brand empty
					$model = '';
					foreach($pmList as $k => $v){
						if(trim($v['code_model'])!=""){
							if(strpos($barcode,$v['code_model'])!==false){
		
								$model = $v['des_model'];
								break;
							}
						}
							
					}
		
		
		
					$tmpArr[] = $model;//model
					$tmpArr[] = '';//MUST FILL
					$tmpArr[] = $aposTitle;//MUST MODIFY put apos title put modify
					$tmpArr[] = '';//empty webite short des
					$pDes = $proDetail->getDetailByCode($barcode);
		
					$tmpArr[] = $pDes['description_product'];// ebay des
		
					$tmpArr[] = $pDes['feature'];//feature
					$tmpArr[] = $pDes['size_mm'];//size
					$tmpArr[] = $pDes['weight_kg'];//weight
					$tmpArr[] = '';//warranty
		
					$positionDash = strrpos($barcode,"-");
					$shortBarcode = trim($barcode);
					if($positionDash > 0){
						$shortBarcode = substr($barcode,0,$positionDash);
					}
					$idColor = str_replace("-","",substr($barcode,$positionDash));
		
					$tmpArr[] = $shortBarcode."_99.jpg";//full color
					$tmpArr[] = trim($barcode)."_0.jpg";//individual color
					$tmpArr[] = '';//zippic empty
					$tmpArr[] = '';//supplyer name empty
					$tmpArr[] = '';//supplier barcode empty
					$tmpArr[] = '';//postage **
		
					$colorDes = $color->getColorDes($idColor);
					$tmpArr[] = $pDes['color'];//color if I can calculate
		
					$tmpArr[] = '';//ebay price
					$tmpArr[] = '';//lovebargain price
					$tmpArr[] = trim(file_get_contents('http://192.168.1.126/products/get-old-apos-product-pricea/barcode/'.trim($barcode)));
					$tmpArr[] = '';//location put to empty
					$tmpArr[] = '';//
					$locList = $loc->getLocationsByProduct($barcode);
					$strLoc = '';
					if(!empty($locList)){
						foreach($locList as $k => $v){
							$strLoc .=$v['code_location'].",";
								
						}
					}
					$tmpArr[] = $strLoc;
					$tmpArr[] = '';
		
					$arrRes[] = $tmpArr;
					fputcsv($fl, $tmpArr);
				}
			}
				
		}
		
		fclose($fl);
		echo $cot;
		d($arrRes);
		
		
		
		
	}

}

?>